#!/usr/bin/python
# -*- coding:utf-8 -*-

import tornado.httpserver
import tornado.ioloop
import tornado.web
import tornado.autoreload
import sys

from sts_handler import StsHandler, StsIndexHandler
from sts_sug_handler import StsSugHandler
from label import LabelHandler, LabelAgentHandler, LabelIndexHandler

reload(sys)
sys.setdefaultencoding('utf-8')
import logging, logging.handlers

MAX_LOG_SIZE = 4 * 1024 * 1024

format = '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s'
logging.basicConfig(level=logging.DEBUG, format=format) #这个格式设置输出到控制台格式
fileshandle = logging.handlers.RotatingFileHandler('sts_web.log', maxBytes=MAX_LOG_SIZE, backupCount=1000)
#fileshandle.suffix = "%Y%m%d_%H%M%S.log"
#fileshandle.setLevel(logging.DEBUG)
formatter = logging.Formatter(format)  #设置写入文件的格式
fileshandle.setFormatter(formatter)

logging.getLogger('').addHandler(fileshandle)



class Application(tornado.web.Application):
    def __init__(self):
        handlers = [
            (r"/api/sts", StsHandler),
            (r"/api/sts_sug", StsSugHandler),
            (r"/label/(.*)", LabelHandler),
            (r"/labelindex", LabelIndexHandler),
            (r"/labelagent", LabelAgentHandler),

            (r"/stsindex", StsIndexHandler),
        ]
        tornado.web.Application.__init__(self, handlers)

def main():
    alarm_wall_record_server = tornado.httpserver.HTTPServer(Application())
    alarm_wall_record_server.listen(8070)
    tornado.ioloop.IOLoop.instance().start()

if __name__ == '__main__':
    main()